package dukeCE.insightTracker.Classes;

import java.util.List;

import dukeCE.insightTracker.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import android.widget.TextView;

public class commentListAdapter extends BaseAdapter {

    private final List<commentListItem> items;
    
    public commentListAdapter(final Context context, final int itemResId,
            final List<commentListItem> items)
    {
        this.items = items;
    }

    public int getCount() {
        return this.items.size();
    }

    public Object getItem(int position) {
        return this.items.get(position);
    }

    public long getItemId(int position) {
        return position;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
    	final commentListItem item = this.items.get(position);
        View itemView = null;
        LayoutInflater inflater = (LayoutInflater) parent.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        itemView = inflater.inflate(R.layout.comment_list_row, null);

        // Set the text of the item
        TextView usernameTxt = (TextView) itemView.findViewById(R.id.textViewCommentUsername);
        TextView descriptionTxt =(TextView) itemView.findViewById(R.id.textViewCommentDescription);
        TextView votingDataTxt = (TextView) itemView.findViewById(R.id.textViewCommentVotingData);
        
        usernameTxt.setText("By: " + item.getUsername());
        descriptionTxt.setText(item.getDescription());
        votingDataTxt.setText("Vote: " + item.getVotingData());
        
        return itemView;
    }
}